package com.vision.sales.sv.db.mgr;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.vision.core.sv.db.mgr.DataManager;
import com.vision.core.sv.db.mgr.ISimpleCriteria;
import com.vision.core.sv.db.mgr.SimpleCriteria;
import com.vision.sales.cm.db.data.SalesmanProduct;

/**
 * 
 * @author Mark
 *
 */
@Repository("salesmanProductManager")
public class SalesmanProductManager extends DataManager<SalesmanProduct> {

	@Override
	public Class<SalesmanProduct> getManagedClass() {
		return SalesmanProduct.class;
	}
	
	@SuppressWarnings("unchecked")
	public SalesmanProduct get(long salesmanId, long productId) {
		ISimpleCriteria crit = SimpleCriteria.forClass(SalesmanProduct.class);
		crit.eq("salesman.id", salesmanId); // This one uses the field name in the class, not the column name in the database
		crit.eq("product.id", productId); // This one uses the field name in the class, not the column name in the database
		List<SalesmanProduct> list = getTemplate().findByCriteria(crit.getDetached());
		return list.isEmpty() ? null : list.get(0);
	}

}
